import { queryDictByType } from '@/api/search/searchOptions';

/**
 * 黑白名单配置options
 * @returns {{typeOptions: *[]}}
 */
export function blackWhiteListOptions() {
	const options: anyObj = {
		// 白资源类型选项
		typeOptions: [
			{ label: '步骤类型', value: 0 },
			{ label: '加载项类型', value: 1 },
			{ label: 'Redis归并类型', value: 2 },
		],
		// 黑名单类型选项
		blackTypeOptions: [
			{ label: 'MAP_CONTENT_TYPE', value: 1 },
			{ label: 'MAP_BEGIN_URL', value: 2 },
			{ label: 'X_REQUESTED_WITH', value: 3 },
			{ label: 'ACCEPT_TYPE', value: 4 },
		],
	};
	for (const key in options) {
		const mapKey = key + 'Map';
		options[mapKey] = {};
		const opArr = options[key];
		opArr.forEach((op: any) => {
			options[mapKey][op.value] = op.label;
		});
	}
	return options;
}

/**
 * 业务服务资源options
 * @returns {{typeOptions: *[], statusOptions: *[], categoryOptions: *[]}}
 */
export function businessServerResourceOptions() {
	const options: anyObj = {
		// 服务资源类型选项
		typeOptions: [
			{ label: 'URL', value: 1 },
			{ label: 'API', value: 2 },
			{ label: 'SQL', value: 3 },
		],
		// 确认状态选项
		statusOptions: [
			{ label: '未确认', value: 0 },
			{ label: '已确认', value: 1 },
		],
		// 资源类别选项
		categoryOptions: [
			{ label: '非首端服务资源', value: 0 },
			{ label: '关键加载项服务资源', value: 1 },
			{ label: '步骤服务资源', value: 2 },
		],
		// 确认类型
		confirmOptions: [
			{ label: '', value: 0 },
			{ label: '手动确认', value: 1 },
			{ label: '自动确认', value: 2 },
		],
	};
	for (const key in options) {
		const mapKey = key + 'Map';
		options[mapKey] = {};
		const opArr = options[key];
		opArr.forEach((op: any) => {
			options[mapKey][op.value] = op.label;
		});
	}
	options.enableOptionsMap = {
		0: '否',
		1: '是',
	};
	return options;
}

/**
 * 专属指标管理options
 */
export function indicatorManagementOptions() {
	const options: anyObj = {
		// 指标来源选项
		sourceOptions: [],
		// 指标值类型选项
		valTypeOptions: [],
		// 标识属性值选项
		effectValOptions: [
			{ label: '是', value: 'yes' },
			{ label: '否', value: 'no' },
			{ label: '是', value: 1 },
			{ label: '否', value: 0 },
		],
		relevanceEffectOptions: [
			{ label: '非关联指标', value: 0 },
			{ label: '是前端关联指标', value: 1 },
			{ label: '是后端关联指标', value: 2 },
			{ label: '是前后端关联指标', value: 3 },
		],
		// 解码方式
		decodeEffectOptions: [
			{ label: '否', value: 0 },
			{ label: 'Base64解码', value: 1 },
			{ label: 'Unicode解码', value: 2 },
			{ label: 'url解码', value: 3 },
			{ label: 'url+unicode解码', value: 4 },
		],
	};
	// 来源
	queryDictByType('indicator_source').then((res: ApiResponse) => {
		res.data.forEach((r: any) => {
			options.sourceOptions.push({
				label: r.label,
				value: r.value,
			});
		});
	});
	queryDictByType('indicator_val_type').then((res: ApiResponse) => {
		res.data.forEach((r: any) => {
			options.valTypeOptions.push({
				label: r.label,
				value: r.value,
			});
		});
	});
	for (const key in options) {
		const mapKey = key + 'Map';
		options[mapKey] = {};
		const opArr = options[key];
		opArr.forEach((op: any) => {
			options[mapKey][op.value] = op.label;
		});
	}
	return options;
}

/**
 * 专属指标管理-关键字配置options
 */
export function identityKeyOptions() {
	const options: anyObj = {
		// 指标来源选项
		sourceOptions: [],
	};
	queryDictByType('indicator_source').then((res: ApiResponse) => {
		res.data.forEach((r: any) => {
			options.sourceOptions.push({
				label: r.label,
				value: r.value,
			});
		});
	});
	for (const key in options) {
		const mapKey = key + 'Map';
		options[mapKey] = {};
		const opArr = options[key];
		opArr.forEach((op: any) => {
			options[mapKey][op.value] = op.label;
		});
	}
	return options;
}

/**
 * 专属指标详情配置-解密方式配置options
 */
export function decryptModeOptions() {
	const options: anyObj = {
		// 解密来源选项
		sourceOptions: [],
		// 加密算法选项
		encAlgOptions: [{ label: 'AES', value: 'AES' }],
		// 加密模式选项
		encModeOptions: [{ label: 'ECB', value: 'ECB' }],
		// 填充选项
		fillValOptions: [
			{ label: 'zeropadding', value: 'zeropadding' },
			{ label: 'pkcs5padding', value: 'pkcs5padding' },
			{ label: 'pkcs7padding', value: 'pkcs7padding' },
		],
		// 数据块选项
		encBinOptions: [{ label: '128', value: '128' }],
		// 解密编码选项
		encodeOptions: [
			{ label: 'base64', value: 'base64' },
			{ label: 'Hex', value: 'Hex' },
		],
	};
	queryDictByType('indicator_source').then((res: ApiResponse) => {
		res.data.forEach((r: any) => {
			options.sourceOptions.push({
				label: r.label,
				value: r.value,
			});
		});
	});
	for (const key in options) {
		const mapKey = key + 'Map';
		options[mapKey] = {};
		const opArr = options[key];
		opArr.forEach((op: any) => {
			options[mapKey][op.value] = op.label;
		});
	}
	return options;
}

/**
 * 专属指标同步options
 */
export function indicatorSyncOptions() {
	const options = {
		// 同步类型
		syncType: [
			{ label: '子资源', value: 'CHILD' },
			{ label: '同一网端资源', value: 'SEGMENT' },
			{ label: '同一业务资源', value: 'BUSINESS' },
			{ label: '父资源', value: 'PARENT' },
		],
	};
	for (const key in options) {
		const mapKey = key + 'Map';
		options[mapKey] = {};
		const opArr = options[key];
		opArr.forEach((op: any) => {
			options[mapKey][op.value] = op.label;
		});
	}
	return options;
}

/**
 * 业务配置option
 */
export function synchronousBusinessOptions() {
	const options: anyObj = {
		//确认状态
		statusOptions: [
			{ label: '确认', value: 1 },
			{ label: '未确认', value: 0 },
		],
		//关键业务
		keyOptions: [
			{ label: '是', value: 1 },
			{ label: '否', value: 0 },
		],
		//步骤设置
		stepSetOptions: [
			{ label: '单步骤', value: 1 },
			{ label: '首末步骤', value: 2 },
			{ label: '多步骤', value: 3 },
		],
	};
	for (const key in options) {
		const mapKey = key + 'Map';
		options[mapKey] = {};
		const opArr = options[key];
		opArr.forEach((op: any) => {
			options[mapKey][op.value] = op.label;
		});
	}
	return options;
}

/**
 * 业务配置option
 */
export function businessProcessOptions() {
	const options: anyObj = {
		//确认状态
		statusOptions: [
			{ label: '确认', value: 1 },
			{ label: '未确认', value: 0 },
		],
		//步骤类型
		stepTypeOptions: [
			{ label: '首步骤', value: 1 },
			{ label: '中间步骤', value: 2 },
			{ label: '末步骤', value: 3 },
		],
		//是否类型
		isOptions: [
			{ label: '是', value: 1 },
			{ label: '否', value: 0 },
		],
	};
	for (const key in options) {
		const mapKey = key + 'Map';
		options[mapKey] = {};
		const opArr = options[key];
		opArr.forEach((op: any) => {
			options[mapKey][op.value] = op.label;
		});
	}
	return options;
}
